import fly from "@/common/js/luch-request";
import config from "@/common/config";
const http = new fly();
http.config.baseUrl = config.baseUrl_v1;
http.interceptor.request(function(config) {
    if (config.method === 'DELETE') {}
    return config;
});

let store = null;
http.interceptor.response(function(res) {
    if (!store) {
        let app = getApp();
        store = app.$store;
    }
    const data = res.data;
    let code = data.code;
    if (code == 402) {
        store && store.commit("User/logout");
        uni.showToast({
            title: '登录状态已过期,请重新登录',
            duration: 2000,
            icon: "none",
            success() {
                uni.navigateTo({
                    url: "/pages/login/index",
                });
            }
        });

    }
    return data || {};
}, function(err) {
    return err;
});

export function verifyCode(code) {
    return code === 200;
}

export default http;